DOC Skip to main content

C++ Sample Depth Stream Viewer

Update on 2025-07-25 06:50:51

Function description: This example mainly demonstrates the use of SDK to get depth data and draw display, get resolution and select settings, display depth images, and exit the program through the ESC_KEY key

 | This example is based on the C++High Level API for demonstration

Firstly, it is necessary to create a pipeline, through which multiple types of streams can be easily opened and closed, and a set of frame data can be obtained

ob::Pipeline pipe;

Get all stream configurations of the depth camera, including stream resolution, frame rate, and frame format

auto profiles = pipe.getStreamProfileList(OB_SENSOR_DEPTH);

std::shared_ptr<ob::VideoStreamProfile> depthProfile = nullptr;
try{
//Find the corresponding Profile according to the specified format, with priority given to Y16 format
depthProfile = profiles->getVideoStreamProfile(640, 480, OB_FORMAT_Y16, 30);
}catch(ob::Error &e){
//If the Y16 format is not found and does not match the format, search for the corresponding profile to open the stream
depthProfile = std::const_pointer_cast<ob::StreamProfile>(profiles->getProfile(OB_PROFILE_DEFAULT))->as<ob::VideoStreamProfile>();
}

Configure which streams to enable or disable in the Pipeline by creating a Configuration, where deep streams will be enabled

std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();
config->enableStream(depthProfile);

Select sequence ID

ob::SequenceIdFilter sequenceIdFilter;
sequenceIdFilter.selectSequenceId(0);

Start the stream configured in Configuration. If no parameters are passed, the default configuration startup stream will be started

pipe.start(config);

Wait for a frame of data in a blocking manner, which is a composite frame containing frame data for all streams enabled in the configuration, and set the waiting timeout time for the frame

auto frameSet = pipe.waitForFrames(100);//Set the waiting time to 100ms

Stop Pipeline, no more frame data will be generated

pipe.stop();

Expected Output

ON THIS PAGE

Add

  • Name:

  • Link Address:

Cancel

Add

  • Name:

  • Link Address:

Cancel
Questions or
Feedback?

Feedback

  • Your feedback matters! Share your thoughts on this page, report errors, or let us know how we can improve to better support your needs. If applicable, please include the specific sentence or section to help us identify and address the issue.